home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / editor / textr12.zip / TEXTREAD.PRG < prev    next >
Text File  |  1996-06-03  |  9KB  |  379 lines

  1. *:*********************************************************************
  2. *:
  3. *:        TDBS Enhanced Text Reading Utility
  4. *:
  5. *:        Revision 1.0
  6. *:        Written by Alan D. Bryant
  7. *:        for eSoft, Inc.
  8. *:        - included with TDBS to illustrate techniques.
  9. *:
  10. *:        Revision 1.1
  11. *:        Modified by Tom Whittenburg
  12. *:        for public release
  13. *:        - updated to include support for non-ansi callers
  14. *:
  15. *:        Revision 1.2
  16. *:        Modified by Jace Carlson
  17. *:        for public release
  18. *:        - updated to provide for increased error checking and cleanup
  19. *:          and to demonstrateas modular programming design
  20. *:
  21. *:  Procs & Fncts: PINITREAD      - initialization
  22. *:               : PREAD          - read & display text file
  23. *:               : PPROMPT        - prompt user and accept input
  24. *:               : XEXITREAD      - cleanup and exit
  25. *:
  26. *:          Calls: PINITREAD      (procedure in TEXTREAD.PRG)
  27. *:               : PREAD          (procedure in TEXTREAD.PRG)
  28. *:               : PPROMPT        (procedure in TEXTREAD.PRG)
  29. *:               : XEXITREAD      (procedure in TEXTREAD.PRG)
  30. *:
  31. *:      Documented 06/03/96 at 22:29                SNAP!  version 4.01a
  32. *:*********************************************************************
  33.  
  34. public gTimeout, gAnsi, gPriv, gLine, gOptdata
  35. public vFile, vHandle, vSize, vDbf, pos, offset
  36. public vStr, key, sel, rV5
  37.  
  38. *
  39. * mainline
  40. *
  41. *
  42.  
  43. do while .t.
  44.    
  45.    private counter, page, lRead
  46.    
  47.    do pInitRead
  48.    
  49.    *
  50.    * get starting offset, then calculate the percentage done
  51.    *
  52.    fseek vHandle moof 0
  53.    percent = (moof * 100) / vSize
  54.    
  55.    counter = 1
  56.    page = 1
  57.    lRead = .t.
  58.    
  59.    *
  60.    * start a loop for our file processing
  61.    *
  62.    do while .t.
  63.       
  64.       if lRead
  65.  
  66.          *
  67.          * read the text file and display it
  68.          *
  69.          do pRead
  70.          
  71.          *
  72.          * get our current file offset, then calculate the percentage done
  73.          *
  74.          fseek vHandle moof 0
  75.          percent = (moof * 100) / vSize
  76.          
  77.          if rV5                                  && end of page
  78.             counter = 1                           && reset counter
  79.             vStr = "Page "+ltrim(str(page))+" ("+ltrim(str(percent))+"%)  <S>top, <P>revious Page, <D>ownload Text, <Enter> Continues."
  80.          else
  81.             vStr = "Page "+ltrim(str(page))+" (100%)  <S>top, <P>revious Page, <D>ownload Text."
  82.          endif
  83.          
  84.       endif
  85.  
  86.       *
  87.       * prompt the user for a command key
  88.       *
  89.       do pPrompt with vStr
  90.       
  91.       *
  92.       * handle the prompt line selection
  93.       *
  94.       do case
  95.          
  96.          *
  97.          * stop
  98.          *
  99.          case sel = "S"
  100.            do xExitRead
  101.          
  102.          *
  103.          * download then exit
  104.          *
  105.          case sel = "D"
  106.             dotbbs type 1 optdata vFile+" /D/NBC/NB"
  107.             do xExitRead
  108.          
  109.          *
  110.          * previous page
  111.          *
  112.          case sel = "P"
  113.             *
  114.             * decrement our page counter (if possible) then goto that
  115.             * record in our temp database
  116.             *
  117.             if page > 1
  118.                page = page - 1
  119.                goto page
  120.                *
  121.                * take the offset of that page, and move our pointer in the
  122.                * text file there and then loop
  123.                *
  124.                fseek vHandle new FPOS 0
  125.                if .not. rV5
  126.                   counter = 1
  127.                endif
  128.                if gAnsi
  129.                   @ 1,0 clear
  130.                else
  131.                   ?
  132.                   ?
  133.                   ?
  134.                endif
  135.                lRead = .t.
  136.             else
  137.                lRead = .f.
  138.             endif
  139.             loop
  140.          
  141.          *
  142.          * <Enter>
  143.          *
  144.          case key = 13
  145.             if rV5                          && if not end of file
  146.                if gAnsi
  147.                   @ 1,0 clear
  148.                else
  149.                   ?
  150.                   ?
  151.                   ?
  152.                endif
  153.                page = page + 1
  154.                if reccount() < page
  155.                   fseek vHandle scratch 0
  156.                   append blank
  157.                   replace FPOS with scratch
  158.                endif
  159.                lRead = .t.
  160.                loop
  161.             endif
  162.          
  163.          *
  164.          * any other keypress and we should do nothing
  165.          *
  166.          otherwise
  167.             lRead = .f.
  168.             loop
  169.          
  170.       endcase                               && end of key selection
  171.       
  172.    enddo && end file read loop
  173.  
  174.    *
  175.    * cleanup and exit
  176.    *
  177.    do xExitRead
  178.    
  179. enddo
  180.  
  181. *
  182. * initialization
  183. *
  184. *!*********************************************************************
  185. *!
  186. *!      Procedure: PINITREAD
  187. *!
  188. *!      Called by: TEXTREAD.PRG                  
  189. *!
  190. *!          Calls: UANSI()        (function in TDBS)
  191. *!               : UPRIV()        (function in TDBS)
  192. *!               : ULINE()        (function in TDBS)
  193. *!               : OPTDATA()      (function in TDBS)
  194. *!
  195. *!           Uses: &VDBF.DBF      
  196. *!               : NEWSTRUC.DBF   
  197. *!
  198. *!*********************************************************************
  199. procedure pInitRead
  200.    store 240 to gTimeout
  201.    store uansi() to gAnsi
  202.    store upriv() to gPriv
  203.    store uline() to gLine
  204.    store optdata() to gOptdata
  205.  
  206.    * make temporary database filename based on unique line number
  207.    *
  208.    vDbf = "TR" + gLine + ".DBF"
  209.  
  210.    *
  211.    * if an old version of that file exists, delete it
  212.    *
  213.    if file(vDbf)
  214.       erase &vDbf
  215.    endif
  216.  
  217.    *
  218.    * create the database in real time
  219.    *
  220.    create newstruc
  221.    use newstruc
  222.    append blank
  223.    replace field_name with "FPOS", field_type with "N", field_len with 10
  224.    use
  225.    create &vDbf from newstruc
  226.    erase newstruc.dbf
  227.  
  228.    *
  229.    * use the database we just created
  230.    *
  231.    use &vDbf
  232.  
  233.    *
  234.    * look for filename in the opt data; it comes after the "&&"
  235.    *
  236.    offset = at(chr(38)+chr(38), gOptdata)
  237.    vFile = trim(substr(gOptdata, offset + 3))
  238.  
  239.    *
  240.    * set initial value for file position
  241.    *
  242.    pos = 0
  243.  
  244.    *
  245.    * open the text file in read mode, and report an error if there was one
  246.    *
  247.    fopen vHandle (vFile) 10
  248.    if vHandle = -1
  249.       ? "Error: "+message(ferror())
  250.       ? "File was: ["+vFile+"]"
  251.       wait
  252.       quit
  253.    endif
  254.  
  255.    *
  256.    * get the size of the file we're reading so we can display the
  257.    * percentage done
  258.    *
  259.    vSize = fsize(vFile)
  260.  
  261.    *
  262.    * do initial screen prep
  263.    *
  264.    if gAnsi
  265.       clear
  266.       set color to w+/r
  267.       @ 0,0 clear to 0,79
  268.       @ 0,1 say "Enhanced Text Reader - "+vFile
  269.       set color to w/n
  270.    else
  271.       ?
  272.       ?
  273.       ? "Enhanced Text Reader - "+vFile
  274.       ?
  275.    endif
  276.  
  277.    *
  278.    * get and store our initial file offset to our temp database
  279.    *
  280.    fseek vHandle pos 0
  281.    append blank
  282.    replace FPOS with pos
  283.  
  284.    *
  285.    * set colors for the text
  286.    *
  287.    if gAnsi
  288.       set color to w/n
  289.    endif
  290.  
  291. return
  292.  
  293. *!*********************************************************************
  294. *!
  295. *!      Procedure: PPROMPT
  296. *!
  297. *!      Called by: TEXTREAD.PRG                  
  298. *!
  299. *!          Calls: XEXITREAD      (procedure in TEXTREAD.PRG)
  300. *!
  301. *!*********************************************************************
  302. procedure pPrompt
  303.    parameter vStr
  304.  
  305.    *
  306.    * display the prompt line and wait for input
  307.    *
  308.    if gAnsi
  309.       set color to w+/r
  310.       @24, 0 say vStr
  311.       ?? replicate(" ", 79 - len(vStr))
  312.       set color to w/n
  313.    else
  314.       ? ""
  315.       ? vStr
  316.    endif
  317.    key = inkey(gTimeout)
  318.    if key = 0
  319.       do xExitRead
  320.    endif
  321.    sel = upper(chr(key))
  322.  
  323. return
  324.  
  325. *!*********************************************************************
  326. *!
  327. *!      Procedure: PREAD
  328. *!
  329. *!      Called by: TEXTREAD.PRG                  
  330. *!
  331. *!          Calls: CRTRIM()       (function in TDBS)
  332. *!
  333. *!*********************************************************************
  334. procedure pRead
  335.  
  336.    do while counter < 21
  337.  
  338.